// ==UserScript==
// @name         Exhentai快捷键翻页
// @namespace    http://tampermonkey.net/
// @description  Exhentai的画廊列表和画廊详情页，使用ad进行左右翻页
// @version      0.0.2-2024-11-30
// @match        https://exhentai.org/*
// @icon         https://exhentai.org/favicon.ico
// @grant        none
// @author       AgMonk
// @homepage     https://gitee.com/AgMonk/tampermonkey-script
// @downloadURL https://gitee.com/AgMonk/tampermonkey-script/raw/master/ehentai/ehentai-page-key.user.js
// @updateURL https://gitee.com/AgMonk/tampermonkey-script/raw/master/ehentai/ehentai-page-key.user.js

// ==/UserScript==

(function () {
    // 前往上一页
    const prevPage = () => {
        // 首页上一页
        document.getElementById("uprev")?.click()

        // 画廊内按钮
        const buttons = [...document.querySelectorAll("td>a")]
        buttons.find(i => i.innerText === '<')?.click()

    }
    // 前往下一页
    const nextPage = () => {
        document.getElementById("unext")?.click()

        // 画廊内按钮
        const buttons = [...document.querySelectorAll("td>a")]
        buttons.find(i => i.innerText === '>')?.click()
    }

    // 监控按键
    document.onkeyup = (e) => {
        const {key, code, target} = e
        // 在input中操作时不执行
        if (target.tagName.toLocaleLowerCase() === 'input') return
        switch (key) {
            case 'a':
                prevPage();
                break;
            case 'd':
                nextPage();
                break;
            default:
        }
        console.log({key, code, target})
    }
})();
